package org.jeecg.modules.simulator.factory.train.load;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.simulator.factory.train.TPathItem;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

/**
 * @program: gp
 * @description:
 * @author: lydms
 * @create: 2024-08-07 14:52
 **/
public class TPathRead {


    public List<TPathItem> tpathItemRead(String path){
        List<TPathItem> pathItemList=new ArrayList<>();
        try {
            String jsonString = new String(Files.readAllBytes(Paths.get(path)));
            JSONArray jsonArray = JSON.parseArray(jsonString);
            for (int i = 0; i < jsonArray.size(); i++) {
                TPathItem tPathItem =new TPathItem();
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                String trainId = jsonObject.getString("trainId");
                tPathItem.setTrainId(trainId);
                String trainNum = jsonObject.getString("trainNum");
                tPathItem.setTrainNum(trainNum);
                String arriveStaionName = jsonObject.getString("arriveStationName");
                tPathItem.setArriveStaionName(arriveStaionName);
                int remainTime = jsonObject.getIntValue("remainTime");
                tPathItem.setRemainTime(remainTime);
                String arriveTime = jsonObject.getString("arriveTime");
                tPathItem.setArriveTime(arriveTime);
                String departTime = jsonObject.getString("departTime");
                tPathItem.setDepartTime(departTime);
                int index = jsonObject.getIntValue("index");
                tPathItem.setIndex(index);
                String lineId   = jsonObject.getString("lineId");
                tPathItem.setLineId(lineId);

                pathItemList.add(tPathItem);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }



        return pathItemList;
    }
}
